<script setup>
import { store } from '@/store'
import { useRouter } from 'vue-router'

const router = useRouter()

const handleCollapse = () => {
  store.isCollapse = !store.isCollapse
};

const handleLoginOut = () => {
  localStorage.removeItem('token')
  router.push('/login')
}
</script>

<template>
  <div class="header">
    <div>
      <el-icon v-show="!store.isCollapse" size="24" class="icon" @click="handleCollapse"><Fold /></el-icon>
      <el-icon v-show="store.isCollapse" size="24" class="icon" @click="handleCollapse"><Expand /></el-icon>
    </div>
    <div>
      <el-dropdown>
        <span class="el-dropdown-link">
          <img src="../assets/images/profile.png" class="user-image" />
          <!--<span class="user-name">{{ store.userInfo.username }}</span>-->
          <div class="user-name">Admin</div>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item  @click="handleLoginOut">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<style lang="less" scoped>
  .header {
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .icon {
      cursor: pointer;
    }

    .el-dropdown-link {
      display: flex;
      align-items: center;
      cursor: pointer;

      .user-image {
        width: 36px;
        height: 36px;
        border-radius: 50%;
      }

      .user-name {
        margin-left: 5px;
        font-size: 20px;
      }
    }
    .el-dropdown-link:focus {
      outline: none;
    }
  }
</style>